package com.dtx.day1.service.impl;

import com.dtx.day1.dao.GoodsDao;
import com.dtx.day5.day05Annotation.Component;
import com.dtx.day1.entity.Goods;
import com.dtx.day1.service.GoodsService;
import com.dtx.day5.day05Annotation.Resource;


import java.math.BigDecimal;
import java.util.Date;

@Component("GoodsService")
public class GoodsServiceImpl implements GoodsService {

    //@Resource
    private GoodsDao goodsDao;

    @Resource
    public void setGoodsDao(GoodsDao goodsDao) {
        this.goodsDao = goodsDao;
    }



    @Override
    public Goods getGoods(Goods goods) {
        goods = new Goods("111","goodsName",new BigDecimal("33.3"),"goodsDesc",new Date());

        return goods;
    }

    @Override
    public boolean addGoods(Goods goods) throws Exception {

        // 判断 商品编号是否为空
        if (goods.getNum() == null) {
            return false;
        }

        // 根据 商品编号，查询商品是否存在

        Goods good = new Goods("111","goodsName",new BigDecimal("33.3"),"goodsDesc",new Date());
        return good.equals(goods);
    }

    @Override
    public Goods findGoods() {
        return goodsDao.findGoods();
    }
}
